package youleche.com.business;

import java.sql.Connection;
import java.util.List;

import youleche.com.common.IDFactory;
import youleche.com.connection.ConnectionFactory;
import youleche.com.factory.DaoFactory;
import youleche.com.idao.IHistoryInfo;
import youleche.com.model.MHistoryInfo;

/**
 * 版本历程业务类
 * @author Administrator
 *
 */
public class BHistoryInfo {
	/**
	 * 数据库连接
	 */
	private Connection con = null;
	
	/**
	 * 处理器
	 */
	private IHistoryInfo handler = null;
	
	/**
	 * 构造器
	 */
	public BHistoryInfo(){
		this.handler = DaoFactory.getDHistoryInfo();
	}
	
	/**
	 * 添加版本历程信息		
	 * @param historyInfo 版本历程
	 * @return 返回影响的行数
	 * @throws Exception 异常
	 */
	public int addHistoryInfo(MHistoryInfo historyInfo)
			throws Exception {
		try{
			this.con = ConnectionFactory.getUlecheWriteConnection();
			historyInfo.setId(IDFactory.getId("meileche", "historyInfo"));
			return this.handler.addHistoryInfo(this.con, historyInfo);
		}finally{
			if(!this.con.isClosed()){
				this.con.close();
			}
		}
	}
	
	/**
	 * 得到版本历程的集合
	 * @return 返回历程集合
	 * @throws Exception异常
	 */
	public List<MHistoryInfo> getHistoryList(String startIndex,
			String endIndex) throws Exception {
		try{
			this.con = ConnectionFactory.getUlecheReadConnection();
			return this.handler.getHistoryList(this.con, startIndex, endIndex);
		}finally{
			if(!this.con.isClosed()){
				this.con.close();
			}
		}
	}

	/**
	 * 得到总条数
	 * @return 返回总条数
	 * @throws Exception
	 */
	public String getHistoryListCount() throws Exception {
		try{
			this.con = ConnectionFactory.getUlecheReadConnection();
			return this.handler.getHistoryListCount(this.con);
		}finally{
			if(!this.con.isClosed()){
				this.con.close();
			}
		}
	}
	
	/**
	 * 根据ID删除版本历程
	 * @return 返回影响的行数
	 * @throws Exception 异常
	 */
	public int deleteHistoryInfoById(String id) throws Exception {
		try{
			this.con = ConnectionFactory.getUlecheWriteConnection();
			return this.handler.deleteHistoryInfoById(this.con, id);
		}finally{
			if(!this.con.isClosed()){
				this.con.close();
			}
		}
	}
}
